package com.nine.pesys.model.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * 比赛动态信息
 * Created by L先森 on 2014/12/20.
 */
@Entity
@Table(name = "tb_game")
public class Game implements Serializable {
    private Long id;
//    用户借用器材
    private String num;
    private String name;
    private String time;
    private Boolean isOver;
    private Float cost;

    private User user;
    private Set<FileInformation> fileInformations = new HashSet<FileInformation>();
    private Set<EquipmentImformation> equipmentImformations = new HashSet<EquipmentImformation>();

    @Id
    @Column(name = "id",length = 10)
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column
    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column
    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    @Column
    public Boolean getIsOver() {
        return isOver;
    }

    public void setIsOver(Boolean isOver) {
        this.isOver = isOver;
    }

    @Column
    public Float getCost() {
        return cost;
    }

    public void setCost(Float cost) {
        this.cost = cost;
    }

    @ManyToOne(targetEntity = User.class,cascade = CascadeType.MERGE)
    @JoinColumn(name = "userId")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "gameId")
    public Set<FileInformation> getFileInformations() {
        return fileInformations;
    }

    public void setFileInformations(Set<FileInformation> fileInformations) {
        this.fileInformations = fileInformations;
    }

//    3.5.3版本中@JoinColumn与mappingBy是互斥的
    @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "gameId")
    public Set<EquipmentImformation> getEquipmentImformations() {
        return equipmentImformations;
    }

    public void setEquipmentImformations(Set<EquipmentImformation> equipmentImformations) {
        this.equipmentImformations = equipmentImformations;
    }
}
